﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Windows;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Unity;
using TripAssistantDesktop.Modules;
using TripAssistantDesktop.TripAssistantWCFService;
using TripAssistantDesktop.ViewModel;

namespace TripAssistantDesktop
{
    public class MyOwnBootStraper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            return this.Container.Resolve<MainWindow>();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();

            App.Current.MainWindow = (Window) this.Shell;
            App.Current.MainWindow.Show();
        }

        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
            BasicHttpBinding myBinding = new BasicHttpBinding();
            EndpointAddress myEndpoint = new EndpointAddress(@"http://localhost:62728/Service.svc");
            ChannelFactory<IAssistantService> assistantServiceFatcory = new ChannelFactory<IAssistantService>(myBinding, myEndpoint);
            IAssistantService assistantService = assistantServiceFatcory.CreateChannel(); 
            Container.RegisterInstance<IAssistantService>(assistantService);
            var users = assistantService.GetIntValue(); 
            Container.RegisterInstance<IUnityContainer>(Container);
            Container.RegisterInstance<ITripsNavigationViewModel>(new TripsNavigationViewModel(Container, Container.Resolve<IEventAggregator>(), Container.Resolve<IAssistantService>()));
            Container.RegisterInstance<IOrdersViewModel>(new OrdersViewModel(Container.Resolve<IEventAggregator>(), Container.Resolve<IAssistantService>()));
            Container.RegisterInstance<ITripViewModel>(new TripViewModel());
            Container.RegisterInstance<IMainWindowViewModel>(new MainWindowViewModel(Container.Resolve<ITripsNavigationViewModel>(), Container.Resolve<ITripViewModel>()));
        }
        protected override void ConfigureModuleCatalog()
        {
            base.ConfigureModuleCatalog();

            ModuleCatalog moduleCatalog = (ModuleCatalog) this.ModuleCatalog;
            //ToDo : Add modules that you need. You can also use Configuration for this.
            moduleCatalog.AddModule(typeof(TripsNavigationModule));
            moduleCatalog.AddModule(typeof(TripViewModule));
            moduleCatalog.AddModule(typeof(OrdersModule));
            moduleCatalog.AddModule(typeof(OrderModule)); 

        }
    }
}
